import { Controller, Get, Query, Body, Post } from '@nestjs/common';
import { QiniuService } from '../utils/qiniu.service';

@Controller('qiniu')
export class QiniuController {
  constructor(private readonly qiniuService: QiniuService) { }

  @Get('token')
  getUploadToken(@Query('directory') directory: string) {
    const token = this.qiniuService.createUploadToken();
    return { uploadToken: token,code:200,message:"七牛云上传凭证, 获取成功" };
  }

  @Post('saveUploadedUrl')
  saveUploadedUrl(@Body() body: { url: string }) {
    return this.qiniuService.saveUploadedUrl(body.url);
  }

  @Get("private-url")
  getPrivateDownloadUrl(@Query('key') key: string) {
    return this.qiniuService.getPrivateDownloadUrl(key);
  }
}